package net.butfly.bus.server.router.impl;

import net.butfly.bus.config.bean.TxBean;
import net.butfly.bus.context.Constants;
import net.butfly.bus.exception.BusRuntimeException;
import net.butfly.bus.server.ServerConfig;
import net.butfly.bus.server.router.DirectoryPolicy;

public class SimpleDirectory implements DirectoryPolicy {
	public String[] lookup(String txCode, String version) {
		TxBean tb = ServerConfig.getTxBean(txCode, version);
		if (tb != null && tb.getNodeAry() != null) {
			return tb.getNodeAry();
		}
		String[] ary = ServerConfig.getNodeIdsByTxMatching(txCode);// 搜索模糊匹配
		if (ary != null) {
			return ary;
		} else {
			throw new BusRuntimeException(Constants.UserError.TX_NOT_FOUND, "没有找到交易代码为\"" + txCode + "\",版本号为\""
					+ version + "\" 的交易，请检查EBox服务端配置（文件或EConsole系统）中的交易（tx）以及 node 的相关配置");
		}
	}
}
